package com.fengke.service.vo;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.builder.ToStringBuilder;

import com.fengke.dao.model.OrderItemModel;
import com.fengke.dao.model.OrderModel;
import com.fengke.dao.model.ProductModel;

public class OrderVO implements Serializable {
	private static final long serialVersionUID = -5868643171926406342L;
	private OrderModel orderModel = new OrderModel();
	private List<OrderItemModel> orderItemModelList = new ArrayList<OrderItemModel>();
	public BigDecimal getAmount()
    {
    	BigDecimal amount = new BigDecimal(0);
    	if(orderItemModelList!=null&&orderItemModelList.size()!=0){
    		ProductModel productModel=orderItemModelList.get(0).getProduct();
    		for(OrderItemModel orderItem : orderItemModelList) {
    			BigDecimal orderItemPrice = orderItem.getPrice();
    			if(orderItemPrice == null) {
    				if(productModel != null) {
    					if(orderItem.getIsAdult()) {
    						orderItemPrice = productModel.getPrice();
    					} else {
    						orderItemPrice = productModel.getChildrenPrice();
    					}
    				}
    				orderItemPrice = new BigDecimal(0);
    			}
    			BigDecimal orderItemQuantity= null;
    			if(orderItem.getQuantity() != null) {
    				orderItemQuantity = new BigDecimal(orderItem.getQuantity());
    			} else {
    				orderItemQuantity = new BigDecimal(1);
    			}
    			amount = amount.add(orderItemPrice.multiply(orderItemQuantity));
    		}
//	    	if(productModel!=null){
//	    		BigDecimal adultAmount=new BigDecimal(0);
//	    		BigDecimal childrenAmount=new BigDecimal(0);
//	    		if(orderModel.getIsShareHouse()!=null&&orderModel.getIsShareHouse()){
//	    			if(productModel.getChildrenPrice()!=null){
//	    				childrenAmount=productModel.getChildrenPrice().multiply(new BigDecimal(orderModel.getChildrenNum()));
//	    			}
//	    			adultAmount=productModel.getPrice().multiply(new BigDecimal(orderModel.getAdultNum()));
//	    		}else{
//	    			if(productModel.getChildrenPrice()!=null){
//	    				childrenAmount=(productModel.getChildrenPrice().add(productModel.getHoursePrice())).multiply(new BigDecimal(orderModel.getChildrenNum()));
//	    			}
//	    			adultAmount=(productModel.getPrice().add(productModel.getHoursePrice())).multiply(new BigDecimal(orderModel.getAdultNum()));
//	    		}
//	    		amount=adultAmount.add(childrenAmount);
//	    	}
    	}
        return amount;
    }
	public Long getTmepAdult(){
    	Long tempAdult=0L;
    	if(orderItemModelList!=null&&orderItemModelList.size()!=0){
    		for(OrderItemModel orderItem:orderItemModelList){
    			if(orderItem!=null&&orderItem.getIsAdult()){
    				tempAdult++;
    			}
    		}
    	}
    	return tempAdult;
    }
    
    public Long getTmepChildren(){
    	Long tempChildren=0L;
    	if(orderItemModelList!=null&&orderItemModelList.size()!=0){
    		for(OrderItemModel orderItem:orderItemModelList){
    			if(orderItem!=null&&!orderItem.getIsAdult()){
    				tempChildren++;
    			}
    		}
    	}
    	return tempChildren;
    }
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
	public OrderModel getOrderModel() {
		return orderModel;
	}
	public void setOrderModel(OrderModel orderModel) {
		this.orderModel = orderModel;
	}
	public List<OrderItemModel> getOrderItemModelList() {
		return orderItemModelList;
	}
	public void setOrderItemModelList(List<OrderItemModel> orderItemModelList) {
		this.orderItemModelList = orderItemModelList;
	}
}
